Sub AddAuthor_Click(Sender As Object, e As EventArgs)
Dim myCommand As SqlCommand
Dim insertCmd As String

'Build a SQL Insert statement string for all the input-form 
'field values. 
insertCmd = "insert into Authors values (@Id, @LName, @FName," _ 
          & "@Phone, @Address, @City, @State, @Zip, @Contract);" 
'Initialize the SqlCommand with the new SQL string. 
myCommand = New SqlCommand(insertCmd, myConnection) 

'Create new parameters for the SqlCommand object and 
'initialize them to the input-form field values. 
myCommand.Parameters.Add(New SqlParameter("@LName", _ SqlDbType.VarChar, 40)) 
myCommand.Parameters("@LName").Value = au_lname.Value 
myCommand.Parameters.Add(New SqlParameter("@FName", _ SqlDbType.VarChar, 20)) 
myCommand.Parameters("@FName").Value = au_fname.Value 
myCommand.Parameters.Add(New SqlParameter("@Phone", _ SqlDbType.Char, 12)) 
myCommand.Parameters("@Phone").Value = phone.Value 
myCommand.Connection.Open() 
'Test to see whether the new row can be added and display the 
'appropriate message box to the user. 
Try 
    myCommand.ExecuteNonQuery() 
    Message.InnerHtml = "<b>Record Added</b><br>" 
Catch ex As SqlException 
    If ex.Number = 2627 Then 
       Message.InnerHtml = "ERROR: A record already exists with " _ 
                         & "the same primary key" 
    Else 
       Message.InnerHtml = "ERROR: Could not add record, please " _ 
                         & "ensure the fields are correctly filled out" 
       Message.Style("color") = "red" 
    End If 
End Try 

myCommand.Connection.Close()

End Sub 
